package com.itheima.jobs;

import com.itheima.constant.RedisConstant;
import com.itheima.util.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @author hql
        * @date 2019-12-04 22:00
        */
public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;
    public void clearImg(){
        //根据Redis中保存的两个set集合进行差值计算，获得垃圾图片名称集合
        Set<String> sdiff = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_RESOURCES);

        if (sdiff!=null){
            for (String s : sdiff) {
                //删除七牛云服务器上的图片
                QiniuUtils.deleteFileFromQiniu(s);
            }
        }
        //删除redis中的set集合
        jedisPool.getResource().del(RedisConstant.SETMEAL_PIC_RESOURCES);
        jedisPool.getResource().del(RedisConstant.SETMEAL_PIC_DB_RESOURCES);

    }
}
